<?php

use Controller\Apps;
use Service\AppTokenService;
use Logic\User\AuthLogic;

/**
 * 会员权限相关
 * Class LoginController
 */
class AuthController extends Apps
{
    protected $needLoginActions = ['publishfeedback','getsellerdetails','changeloginpwd','changheadimg'];

    public function init()
    {
        parent::init();
    }

    /**
     * @api {post} /v1/auth/login 用户登录
     * @apiGroup auth
     * @apiVersion 1.0.0
     * @apiParam (请求-reqdata) {int} mobile 手机号
     * @apiParam (请求-reqdata) {varchar} password 密码
     * @apiUse noReturnParams
     *
     */
    public function loginAction(){
        $platform = $this->clientInfo['platform'] == 'ios' ? 5 : 4;
        $appType = isset($this->clientInfo['appType'])?$this->clientInfo['appType']:'BUYER';
        $userLogic = new AuthLogic();
        $userCheck = $userLogic->login($this->params['mobile'], $this->params['password'], $platform,$appType);
        $this->token = AppTokenService::create($userCheck['id']);
        $this->success('登录成功');
    }

    /**
     * @api {post} /v1/auth/register 用户注册
     * @apiGroup auth
     * @apiVersion 1.0.0
     * @apiParam (请求-reqdata) {int} mobile 手机号
     * @apiParam (请求-reqdata) {varchar} password 密码
     * @apiParam (请求-reqdata) {int} code 验证码
     * @apiParam (请求-reqdata) {int} refferee 推荐人
     * @apiParam (请求-reqdata) {string} role SELLER卖家 BUYER买家
     * @apiUse noReturnParams
     */
    public function registerAction(){
        $params = $this->params;
        $params['platform'] = $this->clientInfo['platform'] == 'ios' ? 5 : 4;
        $userLogic = new AuthLogic();
        $registerRet = $userLogic->register($params);
        $this->token = AppTokenService::create($registerRet['id']);
        $this->success('注册成功');
    }


}